# coding = utf-8
import difflib
import os
import docx
from docx import Document
import codecs
import webbrowser as web



# 遍历指定目录，显示目录下的所有文件名
def eachFile(filepath1,filepath2):
    pathDir1 = os.listdir(filepath1)
    print(pathDir1)
    pathDir2 =os.listdir(filepath2)
    print(pathDir2)

    for i in pathDir1:
        for j in pathDir2:
            if i == j:
                file1 = Document(filepath1 +"\\" + i)
                file2 = Document(filepath2 + "\\" + j)
                para1 = ''
                para2 = ''
                for para in file1.paragraphs:
                    para1 = para1 + para.text + '\n'
                #print(para1)
                for para in file2.paragraphs:
                    para2 = para2 + para.text + '\n'
                #print(para2)
                delta_html = difflib.HtmlDiff().make_file(para1.splitlines(),para2.splitlines())
                if para1.splitlines() != para2.splitlines():
                    with codecs.open('diff.html','a',encoding='utf-8') as f:
                        f.write("文件名称:"+i+delta_html)
                else:
                    print("无差异文件如下："+ i)

# 读取文件内容并打印
def readFile(filename):
    fopen = open(filename, 'r')  # r 代表read
    for eachLine in fopen:
        print
        "读取到得内容如下：", eachLine
    fopen.close()

if __name__ == '__main__':
    # filePath = "D:\\FileDemo\\Java\\myJava.txt"
    # filePathI = "D:\\FileDemo\\Python\\pt.py"
    filePathC = "D:\\临时文件\\file"
    filePathB = "D:\\临时文件\\file2"
    eachFile(filePathC,filePathB)
    # readFile(filePath)
    # writeFile(filePathI)


